#include<iostream>
#include<cstring>
using namespace std;
const int maxv = 10005;
int f[maxv],v,n;

int main(){
	cin>>v>>n;
	int x;
	for(int i =1 ;i<=n;i++){
		cin>>x;
		for(int j=v;j>=x;j--){
			f[j] = max(f[j],f[j-x]+x);
		}
	}
	cout<<v-f[v]<<endl;
}

/**
#include<iostream>
#include<cstring>
using namespace std;
const int maxn = 35;
const int maxv= 20005;

int f[maxn][maxv],a[maxn];

int main(){
	int v,n;
	cin>>v>>n;
	for(int i=1;i<=n;i++){
		cin>>a[i];
	}
	for(int i=1;i<=n;i++){
		for(int j=1;j<=v;j++){
			f[i][j] = f[i-1][j];
			if(j>=a[i])	f[i][j] = max(f[i][j],f[i-1][j-a[i]]+a[i]);
		}
	}
	cout<<v-f[n][v]<<endl;
}
**/